// Vue对象
var vm_ServicerListTable = new Vue({
    el: '#servicerListTable',
    data: {
        servicerList: null
    }
});

/**
 * 客服中心 - 当前未连接的会话
 */
var vm_newRequestListTable = new Vue({
    el: '#newRequestListTable',
    data: {
        newRequestList: []
    },
    methods: {
        getNewRequestListTable: function () {
            this.$http.get("newRequestList").then(function (value) {
                this.newRequestList = value.body;
            }, function (reason) {
                alert(reason.body);
            })
        },
        joinChat: function (uid) {
            this.$http.post("joinChat", {uid: uid}).then(function (value) {
                alert(value.body)
            }, function (reason) {
                alert(reason.body);
            })
        }

    }
})

var vm_ChatingListTable = new Vue({
    el: '#chatingListTable',
    data: {
        chatingList: []
    },
    methods: {
        getChatingList: function () {
            this.$http.get("chatingList").then(function (value) {
                this.chatingList = value.body;
            }, function (reason) {
                alert(reason.body)
            })
        },
        lokeChat: function (uid) {
            vm_oneChat.uid = uid;
            setInterval(vm_oneChat.getChatMsg, 1000);
        }
    }
})

/**
 * 功能盒子
 * funcBox
 */
var vm_funcBox = new Vue({
    el: '#funcBox',
    methods: {
        updateNewRequestList: function () {
            vm_newRequestListTable.getNewRequestListTable();
        },
        updateChatingList: function () {
            vm_ChatingListTable.getChatingList();
        }
    }
})

var vm_oneChat = new Vue({
    el: '#oneChat',
    data: {
        uid: "",
        msgList: []
    },
    methods: {
        getChatMsg: function (uid) {
            this.$http.get("chatMsg", {params: {uid: this.uid}}).then(function (value) {
                this.msgList = value.body
            }, function (reason) {
                this.msgList.length = 0;
                uid = "未选择";
            })
        }
    }
})

// 初始化数据
Vue.http.get("servicesList").then(function (value) {
    vm_ServicerListTable.servicerList = value.body;
});
//////////////////////////////////////////////////////// --------- 循环获取数据区
setInterval(vm_funcBox.updateNewRequestList, 3000);
setInterval(vm_ChatingListTable.getChatingList, 5000);
// 可以更改逻辑，用setTimeout()，以减轻服务器压力